All Questions
Tagged with postgresqlshell-script
22 questions
1vote
1answer
1kviews
how to download postgres data in csv format through bash script?
I am able to connect to db also getting output but it's not coming in proper format. So how to get the output in csv like format and also want to save that in csv format. psql -d <db> -U <...
0votes
1answer
273views
Bash: psql command not found when called inside a function
I have a bash script, where the psql connect string is stored in a variable. After this I have defined three functions. ————————— export PC="usr/bin/psql --host=abx --port=1234 --dbname=A --...
1vote
1answer
980views
Postgres from script shell
Hi I'm trying to create a database with owner ! the owner by default is postgres and I want to change it when a user creates a database read -p "Enter owner database name : " $owner read -p &...
1vote
1answer
965views
Spool/Capture output of COPY command in postgres/Redshift in shell script
I have shell script which will insert data into Redshift/Postgres database using psql command and i am using > for capturing script output. It captures everything but not how many rows inserted. ...
0votes
0answers
156views
Concatenating files with delimiter in for loop
I'm loading data from the filesystem to postgres. I have 500 millions of single files, 1 json in each file. In order to be more efficient with postgres I want to load those in batches not as single ...
0votes
1answer
740views
How to run two sql command sequentially in shell script
I would like to run the two sql commands sequentially but i can't able to achieve it. Here is my shell script #! /bin/bash gsutil cp gs://api-bucket-germany/order_status.csv ./order_status.csv ...
2votes
3answers
70views
Replace text in between certain pattern in UNIX
I want to replace the Millisecond field from file with ":" patter to "." pattern. Input:- Jun 12 2018 3:33:49:000PM Jun 12 2018 3:33:49:850AM Desired Output:- Jun 12 2018 3:33:49.000PM Jun 12 ...
0votes
1answer
79views
set alias to read variable and then use in second command; only works when I execute them manually
I am with CentOS 7 and I want to bind an alias to launch PostgreSQL shell(psql). I defined this alias and append it in /etc/profile.d/alias: alias psql-local="read -p \"PSQL: enter the DB to connect: ...
1vote
1answer
2kviews
How can I start a service after PostGres has booted?
I'm using CentOS 7. I have a nodeJS server I want to run as a service, but I would prefer the service started after my PostGres 9.6 server had booted. I tried specifying after in my service ...
-1votes
1answer
2kviews
How to pass a list to psql on command line?
I'd like to know if there's a way do so something like this : lab-2:/tmp# echo 46692,46694,46696,46704,46708,46709,46713,46730,46736,46574 > deletelist.txt lab-2:/tmp# cat deletelist.txt 46692,...
1vote
4answers
4kviews
Linux - how do I ignore special characters between " "?
My file: (1 sample line) MMP,"01_janitorial,02_cleaning_tools",1,,CUBIC_INCH,"(14) tray capacity, 6" upright with 3" spacing, mounts on 48"W x 24"D, taupe epoxy, fits MetroMax i & MetroMax Q ...
5votes
2answers
10kviews
How to save psql error message output in bash variable?
I have a script that runs several different psql statements. I'm trying to capture the error output from psql when password entered is incorrect. The password is entered in before the check (and when ...
1vote
1answer
770views
Using input from two different files in a for loop
I have a list of files that I want to search across a list of database tables: [root@host hs]# head -n 3 tables rec_playinth120116 rec_playinth120216 rec_playinth120316 [root@host hs]# head -n 3 ...
1vote
1answer
940views
How to run pgpool(or any service) through postgres(any specific) user
I am trying to setup HA solution for PostgreSQL. For that, I am running pgpool service. In that service, it calls a script whenever my primary node fails by calling it like this: /etc/pgpool-II-94/...
0votes
2answers
906views
How to use sqlformat tool with pgAdmin
I am trying to add external SQL formatting utility to pgAdmin. There is an option available in pgAdmin3 in Preferences -> Query tool -> Query editor called external formatting utility I set up ...